import java.util.Scanner;

public class Test2 {

    static long n, m;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        m = in.nextInt();

        long s = 0; // 步数
        long ca = in.nextInt(),cb = in.nextInt(); // 当前位置
        while (in.hasNextInt()) {
            long a = in.nextInt();
            long b = in.nextInt();
            s += step(ca,cb,a,b);
            ca = a;
            cb = b;
        }
        System.out.println(s);
    }

    public static long step(long a, long b, long c, long d) {
        long ans = jl(a, b, c, d);
        ans = Math.min(ans, jl(a, b + m, c, d));
        ans = Math.min(ans, jl(a, b - m, c, d));
        ans = Math.min(ans, jl(a - n, b, c, d));
        ans = Math.min(ans, jl(a + n, b, c, d));
        ans = Math.min(ans, jl(a + n, b - m, c, d));
        ans = Math.min(ans, jl(a + n, b + m, c, d));
        ans = Math.min(ans, jl(a - n, b + m, c, d));
        ans = Math.min(ans, jl(a - n, b - m, c, d));
        return ans;
    }

    public static long jl(long a, long b, long c, long d) {
        return Math.abs(c - a) + Math.abs(d - b);
    }


}
